package com.collect.cameroon.zhiScene.zhiRemind.zhiCustomer.zhiAdmin.zhiPerformance;

import android.content.Context;

import com.collect.cameroon.zhiBase.BasePresenter;
import com.collect.cameroon.zhiBase.BaseSubscriber;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRCustomerPerformanceAdminListEntity;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRCustomerPerformanceListEntity;
import com.collect.cameroon.zhiBean.zhiSend.ZHISPerfermanceEntity;
import com.collect.cameroon.zhiNetApi.ZHIHttpApiProvider;
import com.collect.cameroon.zhiNetApi.ZHIHttpResponse;
import com.collect.cameroon.zhiUtils.RxSchedulers;

import javax.inject.Inject;

public class ZHICustomerPerformanceAdminPersenter extends BasePresenter<ZHICustomerPerformanceAdminContract.View> implements ZHICustomerPerformanceAdminContract.Presenter {

    @Inject
    public ZHICustomerPerformanceAdminPersenter() {

    }

    @Override
    public void getCustomerFollowDLeaderPerformance(Context context, ZHISPerfermanceEntity zhisPerfermanceEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRCustomerPerformanceAdminListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRCustomerPerformanceAdminListEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRCustomerPerformanceAdminListEntity zhirCustomerPerformanceAdminListEntity = (ZHIRCustomerPerformanceAdminListEntity) object;
                            mView.onGetCustomerFollowDLeaderPerformance(zhirCustomerPerformanceAdminListEntity, zhisPerfermanceEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().customerFollowDLeaderPerformance(zhisPerfermanceEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void getCustomerFollowDLeaderPerformanceV2(Context context, ZHISPerfermanceEntity zhisPerfermanceEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRCustomerPerformanceAdminListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRCustomerPerformanceAdminListEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRCustomerPerformanceAdminListEntity zhirCustomerPerformanceAdminListEntity = (ZHIRCustomerPerformanceAdminListEntity) object;
                            mView.onGetCustomerFollowDLeaderPerformance(zhirCustomerPerformanceAdminListEntity, zhisPerfermanceEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().customerFollowDLeaderPerformanceV2(zhisPerfermanceEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void getCustomerFollowDPerformance(Context context, ZHISPerfermanceEntity zhisPerfermanceEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRCustomerPerformanceListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRCustomerPerformanceListEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRCustomerPerformanceListEntity zhirCustomerPerformanceListEntity = (ZHIRCustomerPerformanceListEntity) object;
                            mView.onGetCustomerFollowDPerformance(zhirCustomerPerformanceListEntity, zhisPerfermanceEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().customerFollowDPerformance(zhisPerfermanceEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void getCustomerFollowDPerformanceV2(Context context, ZHISPerfermanceEntity zhisPerfermanceEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRCustomerPerformanceListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRCustomerPerformanceListEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRCustomerPerformanceListEntity zhirCustomerPerformanceListEntity = (ZHIRCustomerPerformanceListEntity) object;
                            mView.onGetCustomerFollowDPerformance(zhirCustomerPerformanceListEntity, zhisPerfermanceEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().customerFollowDPerformanceV2(zhisPerfermanceEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
